home *** CD-ROM | disk | FTP | other *** search
/ Minami 78 / MINAMI78.iso / Extra / winamp53.exe / $R0 / Winamp Modern / scripts / configtarget.m < prev    next >
Text File  |  2005-09-15  |  4KB  |  98 lines

  1. #include <lib/std.mi>
  2.  
  3. // ------------------------------------------------------------------------------------
  4. Global GuiObject target;
  5. Global ComponentBucket buck;
  6. // ------------------------------------------------------------------------------------
  7. Function turnAllOffExcept(GuiObject except);
  8. Function turnOn(GuiObject obj);
  9. Function turnOff(GuiObject obj);
  10. // ------------------------------------------------------------------------------------
  11.  
  12.  
  13. // ------------------------------------------------------------------------------------
  14. // init
  15. // ------------------------------------------------------------------------------------
  16. System.onScriptLoaded() {
  17.   target = getScriptGroup().findObject("skin.config.target");
  18.   buck = getScriptGroup().findObject("my.bucket");
  19.  
  20.   // turn off all
  21.   GuiObject o = NULL;
  22.   turnAllOffExcept(o);
  23. }
  24.  
  25. // ------------------------------------------------------------------------------------
  26. // save scroller position
  27. // ------------------------------------------------------------------------------------
  28. System.onScriptUnloading() {
  29.   if (buck) {
  30.     setPrivateInt("configmenu", "last_scroll", buck.getScroll());
  31.   }
  32. }
  33.  
  34. // ------------------------------------------------------------------------------------
  35. // turn on last open
  36. // ------------------------------------------------------------------------------------
  37. buck.onStartup() {
  38.   setScroll(getPrivateInt("configmenu", "last_scroll", 0));
  39.   Group g = buck.enumChildren(getPrivateInt("configmenu", "last_page", 0));
  40.   if (!g) g = buck.enumChildren(0);
  41.   if (!g) return;
  42.   ToggleButton btn = g.getObject("btn");
  43.   if (btn) btn.leftClick();
  44. }
  45.  
  46. // ------------------------------------------------------------------------------------
  47. // this is called by the bucket button to switch to a new group
  48. // ------------------------------------------------------------------------------------
  49. target.onAction(String action, String param, int x, int y, int p1, int p2, GuiObject source) {
  50.   if (getToken(action,";",0) == "switchto") {
  51.     String grp = getToken(action, ";", 1);
  52.     String is_subpage = getToken(action, ";", 2);
  53.     target.setXmlParam("groupid", grp);
  54.  
  55.     if (is_subpage!="subpage") turnAllOffExcept(source.getParent()); // getParent because the source is the button itself, the parent is the whole group item in the bucket
  56.   }
  57. }
  58.  
  59. // ------------------------------------------------------------------------------------
  60. // turn off all buttons except for the parameter, also save last_page param based on param item
  61. // ------------------------------------------------------------------------------------
  62. turnAllOffExcept(GuiObject except) {
  63.   if (!buck) return;
  64.   int i=0;
  65.   // enumerate all inserted groups, turn them off if they're not our exception
  66.   while (i<buck.getNumChildren()) {
  67.     GuiObject obj = buck.enumChildren(i);
  68.     if (obj == except) { // otherwise record last page
  69.       setPrivateInt("configmenu", "last_page", i);
  70.       i++;
  71.       continue;
  72.     }
  73.     if (obj == NULL) { break; } // shoundnt happen
  74.     turnOff(obj);
  75.     i++;
  76.   }
  77.   // turn on the clicked item
  78.   if (except) turnOn(except);
  79. }
  80.  
  81. // ------------------------------------------------------------------------------------
  82. turnOn(GuiObject obj) {
  83.   Group gobj = obj;
  84.  
  85.   // otherwise we just need this :
  86.   ToggleButton tg = gobj.getObject("btn");
  87.   tg.setActivated(1);
  88. }
  89.  
  90. // ------------------------------------------------------------------------------------
  91. turnOff(GuiObject obj) {
  92.   Group gobj = obj;
  93.  
  94.   // otherwise we just need this :
  95.   ToggleButton tg = gobj.getObject("btn");
  96.   tg.setActivated(0);
  97. }
  98.